package dynamic;

import iautils.IAUtils;
import java.awt.Polygon;
import java.util.ArrayList;
import java.util.Observable;
import visualcbir.util.VSUtils;
import visualcbir.IBackStructureView;
import visualcbir.Model;
import visualcbir.ModelComposed;
import visualcbir.ViewComposed;
import visualcbir.node.ModelNode;

/**
 *
 * @author sheila
 */
public class VSDynamic extends ViewComposed {
    public ArrayList<Edge> aLenEdges;
    public VSDynamic(ModelComposed oModel,  int piNumSubviews){
        super(oModel, piNumSubviews);
    }

    @Override
    public void makeViewFactory(){
        super.makeViewFactory();
        this.aLenEdges=new ArrayList<Edge>();

        //**********************************************************************
        String path = VSUtils.getProperty("imageshistograms");
        ArrayList <int[]>aiHistograms=IAUtils.readHistograms(path);       
        //**********************************************************************
        for (int i = 0; i < this.getNumViews(); i++) {
            for (int j = 0; j < this.getNumViews(); j++) {
                if(i>=j){
                    int len = IAUtils.compareHistograms(aiHistograms.get(i),aiHistograms.get(j));
                    aLenEdges.add(new Edge((ViewNodeDyn)getView(i), (ViewNodeDyn)getView(j),(double)len));
                }
            }
        }
    }

     public void update(Observable o, Object arg) {

         super.getView(0).setCenterPoint(this.getCenterPoint().x, this.getCenterPoint().y);
         for (int i = 10; i < this.getNumViews(); i++) {
                  super.getView(i).setCenterPoint((int)Math.random()*600,(int)Math.random()*450);//3

         }
                   
        super.setViewDimension((int)600, (int)450);
        super.setCenterPoint(this.getViewDimension().width/2,this.getViewDimension().height/2);
        //super.drawViewFactory(arg);//4
    }

    @Override
    public void addView(Model oModelAdded) {
       if(oModelAdded instanceof ModelNode)
            super.addView(new ViewNodeDyn((ModelNode)oModelAdded));
    }

    @Override
    public IBackStructureView makeBackStructureView() {
        return null;
        //throw new UnsupportedOperationException("Not supported yet.");
    }

}
